import { useEffect, useState } from 'react';
import { fetchApiDataList, fetchApiInfo } from '@/api/apiData';
import { message } from 'antd';
export function useApiData(key: any, ...rest: any) {
    const [data, setData] = useState([] as any);
    const [id] = rest;
	useEffect(() => {
			(async () => {
				const apiInfo = await fetchApiInfo(id);
                if (apiInfo.code !== 0) return message.error(apiInfo.msg);
                const res = await fetchApiDataList(apiInfo.data.apiPath)
				if (res.code === 0) return setData(res.data);
				message.error(res.msg);
			})();
		},[ key ]);
	return [ data, setData ];
}